package controller.gui.menubar;

import gui.MapEditorFrame;

import java.awt.Frame;
import java.awt.event.ActionEvent;

import javax.swing.JFileChooser;
import javax.swing.JMenuItem;

import controller.AbstractSaveMenuBarController;
import controller.BrowseUser;
import controller.Controller;
import controller.NullStaticObjectException;

/**rappresenta il Controller che gestisce il pulsante "salva mappa con nome".
 * 
 * @author koldar
 * @version 1.1
 */
public final class SaveMapAsController extends AbstractSaveMenuBarController implements BrowseUser{

	public SaveMapAsController(MapEditorFrame _frame,JMenuItem towire){
		super(_frame,towire);
	}
	
	/**indica la lista di istruzioni da eseguire quando il pulsante "salva mappa con nome" viene premuto
	 * 
	 */
	@Override
	public void wizardInizializer(ActionEvent arg0)throws NullStaticObjectException {
		this.filechooser.setFileFilter(DIRECTORYMDMAPFILTER);
		this.filechooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
		int userchoice=this.filechooser.showSaveDialog(this.frame);
		if (userchoice==JFileChooser.APPROVE_OPTION){
			this.saveMap(this.filechooser.getSelectedFile().getAbsolutePath(),Controller.getCurrentmap());
			this.toBeSavedWithSaveAs.setValue(false);
		}
		this.setToIdle();
	}

}
